package com.apes.fn.rpt.profit.grossProfitProcess.processor;

import com.apes.fn.rpt.profit.grossProfitProcess.CommonGrossProfitProcess;
import com.apes.fn.rpt.profit.grossProfitProcess.GrossProfitProcess;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 年卡消费
 */
@Component
public class YearCardUseExpense extends CommonGrossProfitProcess implements GrossProfitProcess {

    @Override
    public String getSQL(Date taskDate){

        return " SELECT TRUNC(X.CREATE_DATE)                      CREATE_DATE, " +
                "             '预收'                                      INCOME_CATEGORIES, " +
                "             '年卡消费'                                    SERVE_TYPE_NAME, " +
                "             X.DEPT_ID, " +
                "             X.COMPANY_ID, " +
                "             SUM(X.AMOUNT)                             AMOUNT, " +
                "             0                                         TIMES, " +
                "             SUM(X.AMOUNT)                             PRICE_TOTAL, " +
                "             0                                         COST, " +
                "             0                                         CONSUMABLE_USE, " +
                "             0                                         ACCESSORY_COST, " +
                "             0                                         MAN_HOUR_COST, " +
                "             SUM(X.PLATFORM_MANAGEMENT_FEE)            PLATFORM_MANAGEMENT_FEE," +
                "0 vip_in,0 vip_out, " +
                "             0                                         SUPPLY_CHAIN_MANAGEMENT_FEE" +
                "      FROM (SELECT TRUNC(A.DATE_APPROVE) CREATE_DATE, " +
                "                   A.ID, " +
                "                   -1 * B.AMOUNT         AMOUNT, " +
                "                   A.DEPT_ID, " +
                "                   A.COMPANY_ID, " +
                "                   B.PLATFORM_MANAGEMENT_FEE " +
                "            FROM RETAIL_ORDER A, " +
                "                 RETAIL_ORDER_PAYMENT_METHOD B " +
                "            WHERE A.ID = B.RETAIL_ORDER_ID " +
                "              AND PAYMENT_METHOD_TYPE = '10' " +
                "              AND A.DATE_APPROVE >= to_date(:P_DATE, 'YYYY-mm-dd') " +
                "              AND A.DATE_APPROVE < to_date(:P_DATE, 'YYYY-mm-dd') + 1) X " +
                "      GROUP BY X.CREATE_DATE, X.DEPT_ID, " +
                "               X.COMPANY_ID";
    }

    @Override
    public boolean support(String type) {
        return "YearCardUse".equals(type);
    }
}
